import Vue from "vue";
import VueRouter from "vue-router";
import { Notification } from "element-ui";
import Cookie from "../untils/Cookie";
Vue.use(VueRouter);
const router = new VueRouter({
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/login",
      name: "Login",
      component: () => import("../pages/Login/Login.vue"),
      beforeEnter(to, from, next) {
        if (sessionStorage.getItem("token")) {
          Notification({
            title: "提示",
            message: "您已经登录过了",
            type: "warning",
            duration: 4000,
          });
          next("/home");
        } else {
          next();
        }
      },
      meta: {
        type: "login",
        title: "登录",
      },
    },
    {
      path: "/reg",
      name: "Reg",
      component: () => import("../pages/Login/Login.vue"),
      meta: {
        title: "登录",
        type: "reg",
      },
    },
    {
      path: "/detail",
      name: "Detail",
      component: () => import("../pages/Detail"),
      meta: {
        needLogin: false,
        title: "商品详细",
      },
    },
    {
      path: "/fenlei",
      name: "Fenlei",
      component: () => import("../pages/FenLei"),
      meta: {
        needLogin: false,
        title: "全部商品",
      },
    },
    {
      path: "/cart",
      name: "Cart",
      component: () => import("../pages/Cart"),
      meta: {
        needLogin: true,
        title: "我的收藏",
      },
    },
    {
      path: "/orders",
      name: "Orders",
      component: () => import("../pages/Orders"),
      meta: {
        needLogin: true,
        title: "我的订单",
      },
    },

    {
      path: "/wait",
      name: "Wait",
      component: () => import("../pages/Orders/OrderWait"),
      meta: {
        needLogin: true,
        title: "我的出售",
      },
    },
    {
      path: "/mine",
      name: "Mine",
      component: () => import("../pages/Mine"),
      redirect: "/mine/count",
      meta: {
        needLogin: true,
        title: "个人中心",
      },
      children: [
        {
          path: "admin",
          name: "OrdersAd",
          component: () => import("../pages/Orders/admin"),
          meta: {
            needLogin: true,
            title: "订单管理",
          },
        },
        {
          path: "cart",
          name: "Cart",
          component: () => import("../pages/Cart"),
          meta: {
            needLogin: true,
            title: "我的收藏",
          },
        },
        {
          path: "orders",
          name: "Orders",
          component: () => import("../pages/Orders"),
          meta: {
            needLogin: true,
            title: "我的订单",
          },
        },
        {
          path: "wait",
          name: "Wait",
          component: () => import("../pages/Orders/OrderWait"),
          meta: {
            needLogin: true,
            title: "我的出售",
          },
        },
        {
          path: "count",
          name: "Count",
          component: () => import("../pages/Mine/Count"),
          meta: {
            needLogin: true,
            title: "账户设置",
          },
        },
        {
          path: "users",
          name: "Users",
          component: () => import("../pages/Mine/Users"),
          meta: {
            needLogin: true,
            title: "用户管理",
            roles: ["admin", "superstar"],
          },
        },
        {
          path: "goods",
          name: "Goods",
          component: () => import("../pages/Mine/Goods"),
          meta: {
            needLogin: true,
            title: "上传商品",
          },
        },
        {
          path: "category",
          name: "Category",
          component: () => import("../pages/Mine/Category/Add/index.vue"),
          meta: {
            needLogin: true,
            title: "分类管理",
            roles: ["admin", "superstar"],
          },
        },
        {
          path: "suggest",
          name: "Suggest",
          component: () => import("../pages/Mine/Suggest"),
          meta: {
            needLogin: true,
            title: "投诉建议",
          },
        },
      ],
    },
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/home",
      name: "Home",
      component: () => import("../pages/Home"),
    },
  ],
});

export default router;
